from appium import webdriver
from appium.webdriver.common.appiumby import By
import time
import base64

des = {
    "platformName": "Android",
    "appium:platformVersion": "7.1.2",
    "appium:deviceName": "emulator-5554",
    "udid": "emulator-5554",
    "appPackage": "com.android.settings",
    "appActivity": ".Settings"
}

# 初始化驱动对象
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', des)
time.sleep(2)

# # 移除app
# driver.remove_app("com.tencent.wework")

# # 安装app
# driver.install_app(r"C:\TT\习知\课件\我的课件\app自动化\WeCom_android_4.0.19.20104_100001.apk")

# # 判断app是否安装
# print(driver.is_app_installed("com.tencent.wework"))

# my_data = "hello python 坚果"
# # base64加密
# my_data = str(base64.b64encode(my_data.encode('utf-8')), 'utf-8')
# # 文件发送至手机
# driver.push_file("/sdcard/my_text_0619.txt", my_data)

# # 从手机拉取文件
# my_data = driver.pull_file("/sdcard/my_text_0619.txt")
# # base64解码
# my_data = str(base64.b64decode(my_data), encoding='utf-8')
# print(my_data)

# 获取当前页面元素结构
print(driver.page_source)

time.sleep(2)
driver.quit()